//
//  XLVisitorTableViewController.swift
//  XLVeibo
//
//  Created by macbook on 16/6/25.
//  Copyright © 2016年 buWangChuXing. All rights reserved.
//

import UIKit

class XLVisitorTableViewController: UITableViewController {

    //标示用户是否登录
    let isLogin:Bool = XLUserAccountTools.sharedTools.isLogin
    
    //访客视图,加个问好就是需要时才创建
    var vistorView = XLVistor?()
   
    override func loadView() {
        
        //代表用户登录了
        if isLogin {
            
            super.loadView()
            
        }else{
            
        setVistorView()
        
        }
    }
    
    
    //创建访客视图
    private func setVistorView(){
    
        //添加两个item
        setVistorLeftAddRightBarBtnItem()
        //创建
        vistorView = XLVistor()
 // MARK: - 跳转控制器
        vistorView?.close = {[weak self] in
            
            self?.loginBtnItemClick()
         }
        view = vistorView
        
    }
    
    
    //设置访客视图的两个item
    private func setVistorLeftAddRightBarBtnItem(){
    
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(XLVisitorTableViewController.loginBtnItemClick))
        
    
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: #selector(XLVisitorTableViewController.loginBtnItemClick))
        
    }
    
 
    
    
//左边按钮的实现
    @objc private func loginBtnItemClick(){
    
      
        let oauthVc = XLQauchViewController()
        
        let navVc = UINavigationController(rootViewController: oauthVc)
        
        presentViewController(navVc, animated: true, completion: nil)
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
    
            
    }
}
